﻿<!DOCTYPE HTML>
<html>
{include file="public:header_css"}
<link href="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<body>

<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 排课管理 <span class="c-gray en">&gt;</span> 编辑排课
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">

	<div action="" method="post" class="form form-horizontal" id="form-shops-add" enctype="multipart/form-data">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>星期：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select  style="width:60%;" class="input-text" id="week_day">
					{foreach name="week_arr" item="val" key="key"}
					<option value ="{$key}"  style="width:60%;"
							{if condition="$week_info['week_day'] eq  $val "} selected {/if}>
					{$val}
					</option>
					{/foreach}
				</select>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>时段：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select  style="width:60%;" class="input-text" id="period_id">
					{foreach name="period_list" item="val" key="key"}
					<option value ="{$val['period_id']}"  style="width:60%;"
							{if condition="$period_info['id'] eq  $val['period_id'] "} selected {/if}>
					{$val['time']}
					</option>
					{/foreach}
				</select>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>具体班级：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select  style="width:60%;" class="input-text" id="class_id">
					{foreach name="classes_list" item="val" key="key"}
					<option value ="{$val['class_id']}"  style="width:60%;"
							{if condition="$week_info['class_id'] eq  $val['class_id'] "} selected {/if}>
					{$val['class_name']}
					</option>
					{/foreach}
				</select>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>选择教师：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<select  style="width:60%;" class="input-text" id="teacher_id">
					{foreach name="teacher_list" item="val" key="key"}
					<option value ="{$val['teacher_id']}"  style="width:60%;"
							{if condition="$week_info['teacher_id'] eq  $val['teacher_id'] "} selected {/if}>
					{$val['teacher_name']}
					</option>
					{/foreach}
				</select>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input type="hidden" value="{$course_id}" id="course_id">
				<input type="hidden" value="{$course_time_id}" id="course_time_id">
				<button class="btn btn-primary radius" type="submit" id="submit">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
				<a class="btn btn-warning radius" href="{:url('course_arrange/index',array('course_id'=>$course_id))}">&nbsp;&nbsp;返回&nbsp;&nbsp;</a>
			</div>
		</div>
	</div>

</div>
{include file="public:footer_js"}

<script type="text/javascript" src="__STATIC__/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">

    var t1 =0; var t2 =0; var t3 =0; var t4 =0;

    $(function(){

        t1 =$("#week_day").val();
        t2 =$("#period_id").val();
        t3 =$("#class_id").val();
        t4 =$("#teacher_id").val();

        $("#submit").click(function(){

            var course_id	  	= $("#course_id").val();
            var course_time_id  = $("#course_time_id").val();

            var week_day	    = $("#week_day").val();
            var period_id 		= $("#period_id").val();
            var class_id	    = $("#class_id").val();
            var teacher_id	    = $("#teacher_id").val();
            //只修改教师的情况
            if((t1==week_day)&&(t2==period_id)&&(t3==class_id)){
                if((t4!=teacher_id)){
                    //异步提交
                    $.ajax({
                        type:"POST",
                        url:"{:url('edit')}",
                        data:{
                            teacher_id     : teacher_id,
                            week_day       : week_day,
                            period_id      : period_id,
					  		course_id      : course_id,
							course_time_id : course_time_id
                        },
                        async:true,
                        success:function (res) {
                            if(res.code === 0){
                                layer.msg(res.msg,{icon:5,time:2000});
                            }else{
                                layer.msg(res.msg,{icon:6,time:2000});
                                setTimeout(
                                    function(){
                                        location.href = "{:url('course_arrange/index')}"+"?course_id="+res.data;
                                    },
                                    3000);
                            }
                        }
                    });
                    return false;
				}else{
                    layer.msg('未做修改~',{icon:5,time:2000});
                    return false;
				}

            }
            //拼接时间和班级
            var arrange_item1 = week_day+"&"+period_id+"&"+class_id;
            //拼接时间和课程
            var arrange_item2 = week_day+"&"+period_id+"&"+course_id;
            //拼接时间和班级和教师
            var arrange_item3 = arrange_item1+"&"+teacher_id;

            //异步提交
            $.ajax({
                type:"POST",
                url:"{:url('collision_detection_again')}",
                data:{
                    arrange_item1 : arrange_item1,
                    arrange_item2 : arrange_item2
                },
                async:true,
                success:function (res) {
                    if(res.code === 0){
                        layer.msg(res.msg,{icon:5,time:2000});
                    }else{
                        //修改成功
                        //异步提交
                        $.ajax({
                            type:"POST",
                            url:"{:url('edit')}",
                            data:{
                                course_id      : course_id,
                                course_time_id : course_time_id,
                                arrange_time   : JSON.stringify(arrange_item3)
                            },
                            async:true,
                            success:function (res) {
                                if(res.code === 0){
                                    layer.msg(res.msg,{icon:5,time:2000});
                                }else{
                                    layer.msg(res.msg,{icon:6,time:2000});
                                    setTimeout(
                                        function(){
                                            location.href = "{:url('course_arrange/index')}"+"?course_id="+res.data;
                                        },
                                        3000);
                                }
                            }
                        });
                    }
                }
            });
        });
    });
</script>

</body>
</html>